use serde::{Deserialize, Serialize};
use share::core::device_id::DeviceId;

#[derive(Serialize, Deserialize, Debug)]
pub struct DeviceConfig {
    id: DeviceId,
    desc: Option<String>,
}

impl DeviceConfig {
    pub fn new(id: DeviceId) -> DeviceConfig {
        Self { id, desc: None }
    }

    pub fn with_desc(id: DeviceId, desc: String) -> DeviceConfig {
        Self {
            id,
            desc: Some(desc),
        }
    }

    pub fn id(&self) -> &DeviceId {
        &self.id
    }

    pub fn desc(&self) -> Option<&str> {
        self.desc.as_deref()
    }

    pub fn take_all(self) -> (DeviceId, Option<String>) {
        (self.id, self.desc)
    }

    pub fn set_desc(&mut self, desc: String) {
        self.desc = Some(desc);
    }
}
